package com.central.common.feign.fallback

import com.central.common.entity.Post
import com.central.common.feign.PostService
import feign.hystrix.FallbackFactory
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 * @author  fly
 * @date  2021/5/27 17:28
 * @version 1.0
 */
open class PostServiceFallbackFactory : FallbackFactory<PostService>{

    private val log: Logger = LoggerFactory.getLogger(PostServiceFallbackFactory::class.java)


    override fun create(p0: Throwable?): PostService = object : PostService {

        override fun getMyPostLikeNum(userId: Long): Long {

            log.error("获取$userId 的点赞总数失败, 失败原因$p0")
            return 0
        }

        override fun getPostDetail(id: Long): Post? {

            log.error("获取$id 的帖子详情失败, 失败原因$p0")
            return null
        }
    }
}